# shellcheck shell=sh
# shellcheck disable=SC2034 
# shellcheck disable=SC3043
# shellcheck disable=SC2059

# ferreus_orbit Plugins for HPE "DL385 Gen10 Plus"

fo_get_sorted_name(){
  local card
  card="$(echo "$DEVPATH" | cut -d/ -f6)"
  local target
  target="$(echo "$DEVPATH" | cut -d/ -f9)"
  # We expect here 2 SATA SSDs and 12 SAS HDD
  if   [ "${card}" = "host8" ] ; then
    local sc
    sc="$(echo "${DEVPATH}" | cut -d/ -f12)"
    local my_box
    my_box="$(awk '{print $6}' < "/sys/class/scsi_device/${sc}/device/path_info")"
    local id
    id="$(awk '{print $8}' < "/sys/class/scsi_device/${sc}/device/path_info")"
    num=$(( ((my_box - 1) * 4) + id + 1 ))
    local disk
    disk=sd$(fo_get_dev_letter ${num})
  else
    local id=$(($( echo "$target" | cut -d: -f1) - 6))
    local disk
    disk=sd$(fo_get_dev_letter ${id})
  fi
  if [ "$USE_FO_NAME" -lt 1 ]; then
    echo "$disk"
    exit 0
  else
    echo "Box${my_box}-Disk${id}"
    exit 0
  fi
}

fo_get_did(){
  fo_get_id "$1"
}

fo_get_id(){
  if   [ "${card}" = "host8" ] ; then
    local sc
    sc="$(echo "${DEVPATH}" | cut -d/ -f12)"
    local my_box
    my_box="$(awk '{print $6}' < "/sys/class/scsi_device/${sc}/device/path_info")"
    local id
    id="$(awk '{print $8}' < "/sys/class/scsi_device/${sc}/device/path_info")"
    num=$(( ((my_box - 1) * 4) + id + 1 ))
  else
    local num=$(($( echo "$target" | cut -d: -f1) - 6))
  fi
  echo "$num"
  }

FO_BOX_DISPOSITION="| Box {BOX} |{Box{BOX}-Disk1}|{Box{BOX}-Disk2}|{Box{BOX}-Disk3}|{Box{BOX}-Disk4}|\
{new_line}|       |{SN_Box{BOX}-Disk1}|{SN_Box{BOX}-Disk2}|{SN_Box{BOX}-Disk3}|{SN_Box{BOX}-Disk4}|"

FO_DISPOSITION="""
HDD disposition (Front Panel)
__________{UNDERSCORE}___{UNDERSCORE}___{UNDERSCORE}___{UNDERSCORE}__
{BOX1}
|-------|-{MINUS}-|-{MINUS}-|-{MINUS}-|-{MINUS}-|
{BOX2}
|-------|-{MINUS}-|-{MINUS}-|-{MINUS}-|-{MINUS}-|
{BOX3}
¯¯¯¯¯¯¯¯¯¯{HIGHER}¯¯¯{HIGHER}¯¯¯{HIGHER}¯¯¯{HIGHER}¯¯

HDD disposition (Rear Panel):
__{UNDERSCORE}__
|{Box-Disk0}|
|{SN_Box-Disk0}|
|-{MINUS}-|
|{Box-Disk1}|
|{SN_Box-Disk1}|
¯¯{HIGHER}¯¯
"""
 
for b in 1 2 3; do
  fo_box=$(printf "${FO_BOX_DISPOSITION}"|sed "s/{BOX}/${b}/g")
  FO_DISPOSITION=$(printf "${FO_DISPOSITION}"|sed "s/{BOX${b}}/${fo_box}/g")
done

